Pytorch 正则化/动量因子
正则化
$$
J(\theta)=-\frac{1}{m} \sum_{i=1}^{m}\left[y_{i} \ln \hat{y}{i}+\left(1-y{i}\right) \ln \left(1-\hat{y}_{i}\right)\right]
$$
L2-regularization
1 | device = torch.device('cuda:0') |
L1-regularization
pytorch中L1范数没有实现,需要我们自己实现
1 | regularization_loss = 0 |
动量因子
$$
\begin{aligned} w^{k+1} &=w^{k}-\alpha \nabla f\left(w^{k}\right) \ z^{k+1} &=\beta z^{k}+\nabla f\left(w^{k}\right) \ w^{k+1} &=w^{k}-\alpha z^{k+1} \end{aligned}
$$